<?php
   class Booking extends MY_Controller{
	   public function __construct(){
		   parent::__construct();
		   $this->load->model("model_book");
		   $this->load->model("model_home");
           $this->load->helper('mail_helper');
		   $this->load->helper(array('form', 'url'));
		   $this->load->library('form_validation');
		   $this->load->library('cart');
	   }
	   public function index(){
		   $id = (int)$this->uri->segment(4);
		   $data['destination'] = $this->model_home->destination();
		   $data['vietnam'] = $this->destination(1);
		   $data['cambodia'] = $this->destination(2);
		   $data['laos'] = $this->destination(3);
		   $data['holiday'] = $this->holiday();
		   $data['result'] 	= $this->model_cruise->getdata($id);
		   if($data['result'] == NULL){
			   redirect(base_url());
		   }
		   $data['title']     = "Booking";
		   $this->load->view("order/layout",$data);
	   }
	   public function book(){
		   if(!isset($_SESSION['ses_total_cart'])){
			   die("Error! <a href='".base_url()."'>Click here</a> to back home");
		   }
		   $data['title'] = "Submit your booking";
		   $data['destination'] = $this->model_home->destination();
		   $data['vietnam'] = $this->destination(1);
		   $data['cambodia'] = $this->destination(2);
		   $data['hlaos'] = $this->destination(3);
		   $data['holiday'] = $this->holiday();
		   $data['template'] = "booking/book/content";
		   $ship_id = (int)$_SESSION['ses_shipid'];
		   $data['ship']    = $this->model_book->getcruise($ship_id);
		   if($data['ship'] == NULL){ die("False, please try again");}
		   $data['result'] =  $data['ship'];
		   //echo $_SESSION['ses_shipid'];
		   //die();
		   if($this->input->post("sendoks") != NULL ){
			   $this->form_validation->set_rules("firstname","First name","trim|required|min_length[3]");
			   $this->form_validation->set_rules("lastname","Last name","trim|required|min_length[3]");
			   $this->form_validation->set_rules("emailadd","Email address","trim|required|valid_email");
			   $this->form_validation->set_rules("phonenumber","Phone number","trim|required|min_length[9]|numeric");
			   $this->form_validation->set_rules("country","Your country","required");
				if($this->form_validation->run() == FALSE){
					$this->load->view("booking/book/layout",$data);
				}else{
					$title   = $this->input->post("title");
					$firstname    = $this->fillter($this->input->post("firstname"));
					$lastname    = $this->fillter($this->input->post("lastname"));
					$name = $firstname." ".$lastname;
					$email   = $this->fillter($this->input->post("emailadd"));
					$phone   = $this->fillter($this->input->post("phonenumber"));
					$country = $this->fillter($this->input->post("country"));
					$info    = $this->fillter($this->input->post("infomartion"));
					$city    = $this->input->post("city");
					$save_cart = $_SESSION['ses_total_cart'];
					$sheep_name = $this->model_book->get_cruisename($_SESSION['ses_shipid']);
					//$this->debug($session);
					$random = "WLINK".$this->ran().date('His').rand();
			        $order_trans = date('YmdHis').rand();
					$db = array(
						"order_name" 		=> $firstname." ".$lastname,
						"order_email" 		=> $email,
						"order_phone"   	=> $phone,
						"order_country" 	=> $country,
						"order_find"        => $city,
						"order_ip" 			=> $_SERVER['REMOTE_ADDR'],
						"order_singler"     => $_SESSION['ses_total_singler'],
						"order_doubler"     => $_SESSION['ses_total_doubler'],
						"order_twinr"  		=> $_SESSION['ses_total_twinr'],
						"order_price"  		=> $_SESSION['ses_cart_price'],
						"order_startdate"   => $_SESSION['ses_startdate'],
						"order_adults"   	=> $_SESSION['ses_total_adults'],
						"order_childs" 		=> $_SESSION['ses_total_childs'],
						"order_infants"  	=> $_SESSION['ses_total_infants'],
						"order_total_services" => $_SESSION['ses_total_service'],
						"order_services"  	=> $_SESSION['ses_services'],
						"order_extra_service"  => $_SESSION['ses_extra_service'],
						"order_idtrans"		=> $order_trans,
						"order_code" 		=> $random,
						"order_info" 		=> $info,
						"order_content"  	=> $save_cart,
						"order_date"  		=> date("m/d/Y H:i:s"),
						"cruise_id"			=> $_SESSION['ses_shipid'],
						"order_title"		=> $title
					);
					if($_SESSION['rate'] == "vnd"){
						$price = round($db['order_price']/21000);
					}else{
						$price = $db['order_price'];
					}
					//$this->debug($db);
					$onepay = array(
						"virtualPaymentClientURL" => "https://onepay.vn/vpcpay/vpcpay.op",
						"Title" => "VPC 3-Party",
						"vpc_AccessCode" => "3B2F1C9F",
						"vpc_Amount"	=> ($price*100),
						//"vpc_Amount"	=> 500000,
						"vpc_Command"	=> "pay",
						"vpc_Locale"	=> "en",
						"vpc_MerchTxnRef"	=> $db['order_idtrans'],
						"vpc_Merchant"	=> "WLINKUSD",
						"vpc_OrderInfo"	=> $db['order_code'],
						"AVS_Street01"  => "",
						"AVS_City"		=> "",
						"AVS_StateProv" => "",
						"AVS_Country"	=> "",
						"vpc_ReturnURL"	=> base_url()."home/pay_result/pay_w",
						"vpc_TicketNo"	=> $_SERVER['REMOTE_ADDR'],
						"vpc_Version"	=> "2"
					);
					///$this->debug($onepay);
					$_SESSION['ordercode'] = $db['order_idtrans'];
					$_SESSION['orderview'] = $db['order_code'];
					$_SESSION['book_name'] =  $db['order_name'];
					$_SESSION['book_email'] = $db['order_email'];
					$_SESSION['book_info'] = $info;
					$filename = "Booking-wlinktravel.com-".date("d-m-Y-H-i-s");
					$file = "uploads/orderpdf/".$filename.".pdf";
					$cart = unserialize($_SESSION['ses_total_cart']);
					$this->createPDF($cart,$name,$phone,$email,$country,$filename,$sheep_name['cruise_name'],$data['ship']['cruise_special'],$data['ship']['cruise_cancel'],$data['ship']['cruise_pickup'],$info);
					$this->sendmail($cart,$name,$phone,$email,$country,$file,$sheep_name['cruise_name'],$data['ship']['cruise_special'],$data['ship']['cruise_cancel'],$data['ship']['cruise_pickup'],$info);
					$this->model_book->insert_cruise($db);
					$url = $this->onepay_w($onepay);
			    	redirect($url);
				}
			   
		   }else{
		   		$this->load->view("booking/book/layout",$data); 
		   }
	   }
	   public function onepay_w($data){
			// $SECURE_SECRET = "secure-hash-secret";
			$SECURE_SECRET = "320395170BFA37E8AC63A78AF94E14FC";
			
			// add the start of the vpcURL querystring parameters
			$vpcURL = $data["virtualPaymentClientURL"] . "?";
			
			// Remove the Virtual Payment Client URL from the parameter hash as we 
			// do not want to send these fields to the Virtual Payment Client.
			unset($data["virtualPaymentClientURL"]); 
			
			// The URL link for the receipt to do another transaction.
			// Note: This is ONLY used for this example and is not required for 
			// production code. You would hard code your own URL into your application.
			
			// Get and URL Encode the AgainLink. Add the AgainLink to the array
			// Shows how a user field (such as application SessionIDs) could be added
			$data['AgainLink']=urlencode($_SERVER['HTTP_REFERER']);
			//$_POST['AgainLink']=urlencode($_SERVER['HTTP_REFERER']);
			// Create the request to the Virtual Payment Client which is a URL encoded GET
			// request. Since we are looping through all the data we may as well sort it in
			// case we want to create a secure hash and add it to the VPC data if the
			// merchant secret has been provided.
			//$md5HashData = $SECURE_SECRET; Khởi tạo chuỗi dữ liệu mã hóa trống
			$md5HashData = "";
			
			ksort ($data);
			
			// set a parameter to show the first pair in the URL
			$appendAmp = 0;
			
			foreach($data as $key => $value) {
			
			    // create the md5 input and URL leaving out any fields that have no value
			    if (strlen($value) > 0) {
			        
			        // this ensures the first paramter of the URL is preceded by the '?' char
			        if ($appendAmp == 0) {
			            $vpcURL .= urlencode($key) . '=' . urlencode($value);
			            $appendAmp = 1;
			        } else {
			            $vpcURL .= '&' . urlencode($key) . "=" . urlencode($value);
			        }
			        //$md5HashData .= $value; sử dụng cả tên và giá trị tham số để mã hóa
			        if ((strlen($value) > 0) && ((substr($key, 0,4)=="vpc_") || (substr($key,0,5) =="user_"))) {
					    $md5HashData .= $key . "=" . $value . "&";
					}
			    }
			}
			//xóa ký tự & ở thừa ở cuối chuỗi dữ liệu mã hóa
			$md5HashData = rtrim($md5HashData, "&");
			// Create the secure hash and append it to the Virtual Payment Client Data if
			// the merchant secret has been provided.
			if (strlen($SECURE_SECRET) > 0) {
			    //$vpcURL .= "&vpc_SecureHash=" . strtoupper(md5($md5HashData));
			    // Thay hàm mã hóa dữ liệu
			    $vpcURL .= "&vpc_SecureHash=" . strtoupper(hash_hmac('SHA256', $md5HashData, pack('H*',$SECURE_SECRET)));
			}
			
			// FINISH TRANSACTION - Redirect the customers using the Digital Order
			// ===================================================================
			return $vpcURL;
	   }
       public function thank(){
           $data['title']     = "Thanks!";
           $this->load->view("booking/thank/content",$data);
       }
       public function enquiry(){
           $data['ship_budget'] 	= $this->type_ship(1);
           $data['ship_superior'] 	= $this->type_ship(2);
           $data['ship_deluxe'] 	= $this->type_ship(3);
           $data['ship_luxury'] 	= $this->type_ship(4);
           $data['ship_premium'] 	= $this->type_ship(5);
           $data['ship_charter'] 	= $this->type_ship(6);
           $data['title']     = "Enquiry!";
           $data['config']    = $this->config();
           $data['listships'] = $this->listships();
           $this->load->view("order/enquiry/layout",$data);
       }
	   public function sendmail($cart,$name,$number,$email,$country,$file,$cruises,$special,$cancel,$pickup,$info){
		   $mesnger = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                    <html>
                    <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<style type="text/css">
						body{font:12px Verdana, Geneva, sans-serif;}
						h4{
							font:13px Verdana, Geneva, sans-serif;
							text-transform:uppercase
						}
					</style>
                    </head>
                    <body>
                    <h2 style="font-size: 16px;">BOOKING FROM WLINK TRAVEL</h2>
                    <br/>
            ';
			$services = unserialize($_SESSION['ses_services']);
			$ratetype = $_SESSION['rate'];
			$priall = $_SESSION['ses_cart_price'];
			if($ratetype == "vnd"){
				$priceall = round($priall/21000);
			}else{
				$priceall = $priall;
			}
			$cabin = "";
			$service = "";
			foreach($cart as $items){
				$cabin.=' 
				<table>
				<tr><td><span style="font-weight:bold">Cabin type</span> <span style="float:right">:</span></td><td>'.$items['name'].'</td></tr>
				<tr><td>Number of Adults <span style="float:right">:</span></td><td>'.$items['options']['adults'].'</td></tr>
				<tr><td>Number of Children <span style="float:right">:</span></td><td>'.$items['options']['child'].'</td></tr>
				<tr><td>Number of Infants <span style="float:right">:</span></td><td>'.$items['options']['infants'].'</td></tr>';
				if($items['options']['extra'] != 0){
					$cabin.='
						<tr><td>Extra person <span style="float:right">:</span></td><td>'.$items['options']['extra'].'</td></tr>
					';
				}
				$cabin.='
				<tr><td>Check in <span style="float:right">:</span></td><td>'.$items['options']['startdate'].'</td></tr>
				<tr><td>Check out<span style="float:right">:</span></td><td>'.$items['options']['endate'].'</td></tr>
				</table>';
			}
			foreach($services as $serv){
			$service.='
			 <div style="float:left;width:100%;padding-top:8px;">
				<div style="float:left;text-align:justify;">'.$serv['val'].'</div>
			  </div>';
			}
			$mesnger.= '<style>a{text-decoration:none;}
						div{font-family:Tahoma, Geneva, sans-serif;}
						td{vertical-align:top; font-size:12px;font-family:Tahoma, Geneva, sans-serif;padding:2px 0px}
						ul li{font-size:12px;margin-bottom:4px}
						span {font-size:12px;}
						</style>
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td>
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
										<tr>
											<td width="23%" valign="top"  style="border-bottom:1px #ccc solid;"><img src="http://wlinktravel.com/public/images/logo.png" style="margin-top:-18px;margin-left:-10px" /></td>
											<td width="77%" style="text-align:right;border-bottom:1px #ccc solid;"><div style="float:left;width:100%;color:#C01A1A;font-size:33px;font-family:Times New Roman, Times, serif"> PRE-PAID VOUCHER </div>
										<a href="" style="margin-right:29px;color:#4e4e4e;"> <img src="http://paradisecruises.vn/images/print.gif" alt="Print Voucher" width="31" height="18" /><span style="font-size:12px;">Print voucher</span> </a> <a href="mailto:" style="margin-right:29px;color:#4e4e4e;"> <img src="http://paradisecruises.vn/images/mail.gif" alt="Email Voucher" width="27" height="18" /><span style="font-size:12px;">Email voucher</span> </a> <a href="mailto:info@wlinktravel.com" style="color:#4e4e4e;"> <img src="http://paradisecruises.vn/images/bestprint.gif" alt="Best Price Guarantee" width="22" height="18"/><span style="font-size:12px;">Best Price Guarantee</span> </a></td>
										</tr>
								   </table>
								   <hr />
								</td>
						  </tr>
						  <tr>
								<td>
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
									<tr>
									<td valign="top" style="padding-right:20px;"><div style="float:left;width:345px;padding-left:35px;">
										<div style="float:left;width:200px;padding:18px 0 1px;color:#C01A1A;font-size:18px">Customer info
										<hr style="color:#929292;margin-top:2px;"/>
									  </div>
										<table>
										<tr>
											<td style="color:#000;">Full name <span style="float:right">:</span></td>
											<td>'.$name.'</td>
										  </tr>
										<tr>
											<td>Phone <span style="float:right">:</span></td>
											<td>'.$number.'</td>
										  </tr>
										<tr>
											<td>Email add <span style="float:right">:</span></td>
											<td>'.$email.'</td>
										  </tr>
										<tr>
											<td>Country <span style="float:right">:</span></td>
											<td>'.$country.'</td>
										  </tr>
									  </table>
										<div style="float:left;width:100%;padding:86px 0 1px;color:#C01A1A;font-size:18px"> Special Requests
										<hr style="color:#929292;margin-top:2px;"/>
									  </div>
										<div style="float:left;width:100%;min-height:144px;">'.$info.'</div>
									  </div></td>
									<td valign="top"><div style="float:left;width:100%;padding:18px 0 1px;color:#C01A1A;font-size:18px">'.$cruises.' Reservation
										<hr style="color:#929292;margin-top:2px;"/>
									  </div>
										<div style="float:left;width:100%;padding-top:8px;">
										<div style="float:left; font-weight:bold;text-align:justify;">Cabin Confirmation:</div>
									  </div>
									  '.$cabin.'
									<div style="float:left;width:100%;padding-top:8px;">
									<div style="float:left;font-weight:bold;text-align:justify;">Transfer Service:</div>
								  </div>
									'.$service.'
									<table>
									<tr>
										<td>Total price:</td>
										<td style="float:right;font-weight:bold;font-size:16px;color:#C01A1A;"> $'.$priceall.'</td>
									  </tr>
									<tr>
										<td colspan="2" style="padding-top:8px;font-weight:bold;font-style:italic;">Note: VAT (10%) and Service charge (5%) included</td>
									  </tr>
								  </table></td>
							  </tr>
								<tr>
								<td valign="top" width="345px"  style="padding-right:20px;"><div style="float:left;width:345px;padding-left:35px;">
									<div style="float:left;width:100%;padding:18px 0 1px;color:#C01A1A;font-size:18px"> Important Note
									<hr style="color:#929292;margin-top:2px;"/>
								  </div>
									<div style="float:left;width:100%;min-height:144px;">'.$pickup.'</div>
								  </div></td>
								<td valign="top"><div style="float:right;padding-right:35px;width:345px;">
									<div style="float:left;width:100%;padding:18px 0 1px;color:#C01A1A;font-size:18px">Cancellation Policy
									<hr style="color:#929292;margin-top:2px;"/>
								  </div>
									<div style="min-height:100px;padding-bottom:10px">'.$cancel.'</div>
								  <div style="float:left;width:100%;padding:18px 0 1px;color:#C01A1A;font-size:18px">Special Check-in Instruction
									<hr style="color:#929292;margin-top:2px;"/>
								  </div>
								    <div style="min-height:100px;padding-bottom:10px">'.$special.'</div>
								  </div></td>
							  </tr>
							  </table>
						   </td>
					   </tr>
					   <tr>
						   <td>
							  <div style="padding:0 35px;">
								 <div style="float:left;width:100%;padding:18px 0 1px;color:#C01A1A;font-size:18px">Need Help
									  <hr style="color:#929292;margin-top:2px;"/>
								 </div>
							  </div>
				  <table border="0" cellpadding="0" cellspacing="0">
							<tr>
								  <td>
										<div style="float:left;padding-top:8px;"> <span style="color:#000;">For any questions related to your reservation, please do feel free contact us directly on:<br>
										</span> <strong style="color:#C01A1A">+84 43939 2929</strong> (hotline number) or <br>
									  at <strong style="color:#C01A1A">info@wlinktravel.com</strong> </div></td>
								  <td width="300px">
										<div style="float:left;color:#11252f;font-size:28px;">Have a wonderful trip!</div></div>
								  </td>
							</tr>  
						  </table>
						</td>
				  </tr> 
				</table>';
		    $mesnger .= '</body></html> ';
			//return $mesnger;
			send_mail_helper('info@wlinktravel.com', 'BOOKING FROM WLINK TRAVEL', htmlspecialchars_decode($mesnger),$file);
		}
	   public function createPDF($cart,$name,$number,$email,$country,$filename,$cruise,$special,$cancel,$pickup,$info){
			$services = unserialize($_SESSION['ses_services']);
			$ratetype = $_SESSION['rate'];
			$priall = $_SESSION['ses_cart_price'];
			if($ratetype == "vnd"){
				$priceall = round($priall/21000);
			}else{
				$priceall = $priall;
			}
			$cabin = "";
			$service = "";
			foreach($cart as $items){
				$cabin.='
				 <style type="text/css">
					body{font:12px Verdana, Geneva, sans-serif;}
					h4{
						font:13px Verdana, Geneva, sans-serif;
						text-transform:uppercase
					}
				</style>
				<table>
				<tr><td><span style="font-weight:bold">Cabin type</span> <span style="float:right">:</span></td><td>'.$items['name'].'</td></tr>
				<tr><td>Number of Adults <span style="float:right">:</span></td><td>'.$items['options']['adults'].'</td></tr>
				<tr><td>Number of Children <span style="float:right">:</span></td><td>'.$items['options']['child'].'</td></tr>
				<tr><td>Number of Infants <span style="float:right">:</span></td><td>'.$items['options']['infants'].'</td></tr>';
				if($items['options']['extra'] != 0){
					$cabin.='
						<tr><td>Extra person <span style="float:right">:</span></td><td>'.$items['options']['extra'].'</td></tr>
					';
				}
				$cabin.='
				<tr><td>Check in <span style="float:right">:</span></td><td>'.$items['options']['startdate'].'</td></tr>
				<tr><td>Check out<span style="float:right">:</span></td><td>'.$items['options']['endate'].'</td></tr>
				</table>';
			}
			foreach($services as $serv){
			$service.='
			 <div style="float:left;width:100%;padding-top:8px;">
				<div style="float:left;text-align:justify;">'.$serv['val'].'</div>
			  </div>';
			}
			$html = '<style>a{text-decoration:none;}
						div{font-family:Tahoma, Geneva, sans-serif;}
						td{vertical-align:top; font-size:12px;font-family:Tahoma, Geneva, sans-serif;padding:2px 0px}
						ul li{font-size:12px;margin-bottom:4px}
						span {font-size:12px;}
						</style>
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td>
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
										<tr>
											<td width="23%" valign="top"  style="border-bottom:1px #ccc solid;"><img src="public/images/logo.png" style="margin-top:-18px;margin-left:-10px" /></td>
											<td width="77%" style="text-align:right;border-bottom:1px #ccc solid;"><div style="float:left;width:100%;color:#C01A1A;font-size:33px;font-family:Times New Roman, Times, serif"> PRE-PAID VOUCHER </div>
										<a href="" style="margin-right:29px;color:#4e4e4e;"> <img src="http://paradisecruises.vn/images/print.gif" alt="Print Voucher" width="31" height="18" /><span style="font-size:12px;">Print voucher</span> </a> <a href="mailto:" style="margin-right:29px;color:#4e4e4e;"> <img src="http://paradisecruises.vn/images/mail.gif" alt="Email Voucher" width="27" height="18" /><span style="font-size:12px;">Email voucher</span> </a> <a href="mailto:info@wlinktravel.com" style="color:#4e4e4e;"> <img src="http://paradisecruises.vn/images/bestprint.gif" alt="Best Price Guarantee" width="22" height="18"/><span style="font-size:12px;">Best Price Guarantee</span> </a></td>
										</tr>
								   </table>
								   <hr />
								</td>
						  </tr>
						  <tr>
								<td>
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
									<tr>
									<td valign="top" style="padding-right:20px;"><div style="float:left;width:345px;padding-left:35px;">
										<div style="float:left;width:200px;padding:18px 0 1px;color:#C01A1A;font-size:18px">Customer info
										<hr style="color:#929292;margin-top:2px;"/>
									  </div>
										<table>
										<tr>
											<td style="color:#000;">Full name <span style="float:right">:</span></td>
											<td>'.$name.'</td>
										  </tr>
										<tr>
											<td>Phone <span style="float:right">:</span></td>
											<td>'.$number.'</td>
										  </tr>
										<tr>
											<td>Email add <span style="float:right">:</span></td>
											<td>'.$email.'</td>
										  </tr>
										<tr>
											<td>Country <span style="float:right">:</span></td>
											<td>'.$country.'</td>
										  </tr>
									  </table>
										<div style="float:left;width:100%;padding:86px 0 1px;color:#C01A1A;font-size:18px"> Special Requests
										<hr style="color:#929292;margin-top:2px;"/>
									  </div>
										<div style="float:left;width:100%;min-height:144px;">'.$info.'</div>
									  </div></td>
									<td valign="top"><div style="float:left;width:100%;padding:18px 0 1px;color:#C01A1A;font-size:18px">'.$cruise.' Reservation
										<hr style="color:#929292;margin-top:2px;"/>
									  </div>
										<div style="float:left;width:100%;padding-top:8px;">
										<div style="float:left; font-weight:bold;text-align:justify;">Cabin Confirmation:</div>
									  </div>
									  '.$cabin.'
									<div style="float:left;width:100%;padding-top:8px;">
									<div style="float:left;font-weight:bold;text-align:justify;">Transfer Service:</div>
								  </div>
									'.$service.'
									<table>
									<tr>
										<td>Total price:</td>
										<td style="float:right;font-weight:bold;font-size:16px;color:#C01A1A;"> $'.$priceall.'</td>
									  </tr>
									<tr>
										<td colspan="2" style="padding-top:8px;font-weight:bold;font-style:italic;">Note: VAT (10%) and Service charge (5%) included</td>
									  </tr>
								  </table></td>
							  </tr>
								<tr>
								<td valign="top" width="345px"  style="padding-right:20px;"><div style="float:left;width:345px;padding-left:35px;">
									<div style="float:left;width:100%;padding:18px 0 1px;color:#C01A1A;font-size:18px"> Important Note
									   <hr style="color:#929292;margin-top:2px;"/>
								    </div>
									<i  style="font-size:12px;">(if you book our transportation service)</i>
									<div style="min-height:100px;padding:10px 0px">'.$pickup.'</div>
								  </div></td>
								<td valign="top"><div style="float:right;padding-right:35px;width:345px;">
									<div style="float:left;width:100%;padding:18px 0 1px;color:#C01A1A;font-size:18px">Cancellation Policy
									<hr style="color:#929292;margin-top:2px;"/>
								  </div>
									<div style="min-height:100px;padding:10px 0px">
									<table width="400" border="0">
									  <tr>
										<td height="67">'.$cancel.'</td>
									  </tr>
									</table>
									</div>
									<div style="clear:left"></div>
									<div style="width:100%;padding:18px 0 1px;padding-top:15px;color:#C01A1A;font-size:18px;margin-top:10px">Special Check-in Instruction
									<hr style="color:#929292;margin-top:2px;"/>
								  </div>
									<div style="min-height:100px;padding:10px 0px">'.$special.'</div>
								  </div></td>
							  </tr>
							  </table>
						   </td>
					   </tr>
					   <tr>
						   <td>
							  <div style="padding:0 35px;">
								 <div style="float:left;width:100%;padding:18px 0 1px;color:#C01A1A;font-size:18px">Need Help
									  <hr style="color:#929292;margin-top:2px;"/>
								 </div>
							  </div>
				  			<table border="0" cellpadding="0" cellspacing="0">
							<tr>
								  <td>
										<div style="float:left;padding-top:8px;"> <span style="color:#000;">For any questions related to your reservation, please do feel free contact us directly on:<br>
										</span> <strong style="color:#C01A1A">+84 43939 2929</strong> (hotline number) or <br>
									  at <strong style="color:#C01A1A">info@wlinktravel.com</strong> </div></td>
								  <td width="300px">
										<div style="float:left;color:#11252f;font-size:28px;">Have a wonderful trip!</div></div>
								  </td>
							</tr>  
						  </table>
						</td>
				  </tr> 
				</table>';
					
			$this->load->library('Mpdf');
			//$name_pdf = date("dmYHis").rand();
			$mpdf = new Pdf();
			$mpdf->SetAutoFont(AUTOFONT_ALL);
			$mpdf->WriteHTML($html);
			$mpdf->Output("uploads/orderpdf/$filename.pdf",'F');
		}
	   public function findtour($tour){
			switch($tour){
				case "1" : $type = "1 day"; break;
				case "2" : $type = "2 days 1 night"; break;
				case "3" : $type = "3 days 2 nights"; break;
				case "4" : $type = "4 days 3 nights"; break;
				case "5" : $type = "More than 4 days"; break;
				default  : $type = "2 days 1 night"; break;
			}
		return $type;
	  }
	  public function ran(){
			$input = array("a","b","c","d","e","f","g","h","j","k","l","m","z","x","y","q");
			$rand_keys = array_rand($input, 3);
			return strtoupper($input[$rand_keys[0]].$input[$rand_keys[1]].$input[$rand_keys[2]]);
	   }
   }